package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MeowInventory;
import com.ruoyi.system.service.IMeowInventoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存管理Controller
 * 
 * @author ruoyi
 * @date 2025-06-24
 */
@Controller
@RequestMapping("/system/inventory")
public class MeowInventoryController extends BaseController
{
    private String prefix = "system/inventory";

    @Autowired
    private IMeowInventoryService meowInventoryService;

    @RequiresPermissions("system:inventory:view")
    @GetMapping()
    public String inventory()
    {
        return prefix + "/inventory";
    }

    /**
     * 查询库存管理列表
     */
    @RequiresPermissions("system:inventory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MeowInventory meowInventory)
    {
        startPage();
        List<MeowInventory> list = meowInventoryService.selectMeowInventoryList(meowInventory);
        return getDataTable(list);
    }

    /**
     * 导出库存管理列表
     */
    @RequiresPermissions("system:inventory:export")
    @Log(title = "库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MeowInventory meowInventory)
    {
        List<MeowInventory> list = meowInventoryService.selectMeowInventoryList(meowInventory);
        ExcelUtil<MeowInventory> util = new ExcelUtil<MeowInventory>(MeowInventory.class);
        return util.exportExcel(list, "库存管理数据");
    }

    /**
     * 新增库存管理
     */
    @RequiresPermissions("system:inventory:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存管理
     */
    @RequiresPermissions("system:inventory:add")
    @Log(title = "库存管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MeowInventory meowInventory)
    {
        return toAjax(meowInventoryService.insertMeowInventory(meowInventory));
    }

    /**
     * 修改库存管理
     */
    @RequiresPermissions("system:inventory:edit")
    @GetMapping("/edit/{productId}")
    public String edit(@PathVariable("productId") String productId, ModelMap mmap)
    {
        MeowInventory meowInventory = meowInventoryService.selectMeowInventoryByProductId(productId);
        mmap.put("meowInventory", meowInventory);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存管理
     */
    @RequiresPermissions("system:inventory:edit")
    @Log(title = "库存管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MeowInventory meowInventory)
    {
        return toAjax(meowInventoryService.updateMeowInventory(meowInventory));
    }

    /**
     * 删除库存管理
     */
    @RequiresPermissions("system:inventory:remove")
    @Log(title = "库存管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(meowInventoryService.deleteMeowInventoryByProductIds(ids));
    }
}
